//
//  ZYUrlSessionManager.h
//  ZYWebImage
//
//  Created by wangzhipan on 2025/4/11.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "IZYURLResponseSerializer.h"
#import "ZYSecurityPolicy.h"
#import "IZYURLResponseSerializer.h"
#import "AFNetworkReachabilityManager.h"

NS_ASSUME_NONNULL_BEGIN

@interface ZYUrlSessionManager : NSObject 
@property (nonatomic, strong, readonly) NSURLSession *session;
@property (nonatomic, strong, readonly) NSOperationQueue *queue;
//https 中ssl 证书验证策略
@property (nonatomic, strong, nullable) ZYSecurityPolicy *securityPolicy;

@property (nonatomic, strong) id <IZYURLResponseSerializer> responseSerializer;

//网络状态
@property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;

//The data, upload  tasks currently run by the managed session.
@property (nonatomic, strong, readonly) NSArray <NSURLSessionTask *> *tasks;

@property (nonatomic, strong, readonly) NSArray <NSURLSessionTask *> *dataTasks;

@property (nonatomic, strong, readonly) NSArray <NSURLSessionTask *> *uploadTasks;

//请求完成，返回的response数据队列，默认在main_queue处理
@property (nonatomic, copy, nullable) dispatch_queue_t completedQueue;


- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)sessionConfiguration;

// 作废sessionConfiguration以及cancel所有任务
- (void)invalidateSessionCancelingTasks:(BOOL)cancelPendingTasks resetSession:(BOOL)resetSession;

//get\post\head请求
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
                               completedBlock:(nullable void(^)(NSURLResponse *response, id _Nullable rspObj, NSError * _Nullable error))completedBlock;

//小数据上传
- (NSURLSessionDataTask *)uploadTaskWithRequest:(NSURLRequest *)request
                                 uploadProgress:(nullable void(^)(NSUInteger currentSentSize, NSUInteger totalSize))uploadProgress
                                 completedBlock:(nullable void(^)(NSURLResponse *response, id _Nullable rspObj, NSError * _Nullable error))completedBlock;
//大数据上传
- (NSURLSessionDataTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request
                                         uploadProgress:(nullable void(^)(NSUInteger currentSentSize, NSUInteger totalSize))uploadProgress
                                         completedBlock:(nullable void(^)(NSURLResponse *response, id _Nullable rspObj, NSError * _Nullable error))completedBlock;
@end

NS_ASSUME_NONNULL_END
